(function() {
	
this.pasta = this.pasta || {};
this.pasta.webgui = this.pasta.webgui || {};

this.pasta.webgui.Loader = pasta.webgui.ContainerControl.extend(
{
	init : function() 
	{
		this._super();
		
		this.setWidth(66);
		this.setHeight(20);
		
		var space = 4;
		
		this.step = 1;
		this.color = "rgba(255, 255, 255,";
		
		this.shp1 = new pasta.webgui.Shape();
		this.shp1.setLeft(0);
		this.shp1.setTop(0);
		this.shp1.setWidth(10);
		this.shp1.setHeight(10);
		this.shp1.setBorderColor(this.color + " 0)");
		this.addControl(this.shp1);
		
		this.shp2 = new pasta.webgui.Shape();
		this.shp2.setLeft(this.shp1.getLeft() + this.shp1.getWidth() + space);
		this.shp2.setTop(this.shp1.getTop());
		this.shp2.setWidth(this.shp1.getWidth());
		this.shp2.setHeight(this.shp1.getHeight());
		this.shp2.setBorderColor(this.color + " 0)");
		this.addControl(this.shp2);
		
		this.shp3 = new pasta.webgui.Shape();
		this.shp3.setLeft(this.shp2.getLeft() + this.shp2.getWidth() + space);
		this.shp3.setTop(this.shp1.getTop());
		this.shp3.setWidth(this.shp1.getWidth());
		this.shp3.setHeight(this.shp1.getHeight());
		this.shp3.setBorderColor(this.color + " 0)");
		this.addControl(this.shp3);
		
		this.shp4 = new pasta.webgui.Shape();
		this.shp4.setLeft(this.shp3.getLeft() + this.shp3.getWidth() + space);
		this.shp4.setTop(this.shp1.getTop());
		this.shp4.setWidth(this.shp1.getWidth());
		this.shp4.setHeight(this.shp1.getHeight());
		this.shp4.setBorderColor(this.color + " 0)");
		this.addControl(this.shp4);
		
		this.shp5 = new pasta.webgui.Shape();
		this.shp5.setLeft(this.shp4.getLeft() + this.shp4.getWidth() + space);
		this.shp5.setTop(this.shp1.getTop());
		this.shp5.setWidth(this.shp1.getWidth());
		this.shp5.setHeight(this.shp1.getHeight());
		this.shp5.setBorderColor(this.color + " 0)");
		this.addControl(this.shp5);
		
		this.lbl = new pasta.webgui.Label();
		this.lbl.setLeft(0);
		this.lbl.setTop(14);
		this.lbl.setWidth(this.getWidth());
		this.lbl.setCaption("loading...");
		this.lbl.font.setColor("#FFFFFF");
		this.lbl.setAlign("center");
		this.addControl(this.lbl);
		
		this.timer = new pasta.util.Timer();
		this.timer.setTimeInterval(100);
		this.timer.getOnTimer().setHandler(this, this.timerTimer);
		this.timer.setEnabled(true);
	},
	
	setVisible : function(data)
	{
		this._super(data);
		
		if (this.timer != null)
			this.timer.setEnabled(data);
	},
	
	timerTimer : function(sender)
	{
		this.step++;
		
		if (this.step > 16)
			this.step = 1;
		
		switch (this.step)
		{
			case 1 :
					this.shp1.setBgColor(this.color + " 1)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
			case 2 :
					this.shp1.setBgColor(this.color + " 0.6)");
					this.shp2.setBgColor(this.color + " 1)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
			case 3 :
					this.shp1.setBgColor(this.color + " 0.3)");
					this.shp2.setBgColor(this.color + " 0.6)");
					this.shp3.setBgColor(this.color + " 1)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
			case 4 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 0.3)");
					this.shp3.setBgColor(this.color + " 0.6)");
					this.shp4.setBgColor(this.color + " 1)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
			case 5 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 0.3)");
					this.shp4.setBgColor(this.color + " 0.6)");
					this.shp5.setBgColor(this.color + " 1)");
					break;
			case 6 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 0.3)");
					this.shp5.setBgColor(this.color + " 0.6)");
					break;
			case 7 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 0.3)");
					break;
			case 8 :
			case 16 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
			case 9 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 1)");
					break;
			case 10 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 1)");
					this.shp5.setBgColor(this.color + " 0.6)");
					break;
			case 11 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 1)");
					this.shp4.setBgColor(this.color + " 0.6)");
					this.shp5.setBgColor(this.color + " 0.3)");
					break;
			case 12 :
					this.shp1.setBgColor(this.color + " 0)");
					this.shp2.setBgColor(this.color + " 1)");
					this.shp3.setBgColor(this.color + " 0.6)");
					this.shp4.setBgColor(this.color + " 0.3)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
			case 13 :
					this.shp1.setBgColor(this.color + " 1)");
					this.shp2.setBgColor(this.color + " 0.6)");
					this.shp3.setBgColor(this.color + " 0.3)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
			case 14 :
					this.shp1.setBgColor(this.color + " 0.6)");
					this.shp2.setBgColor(this.color + " 0.3)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
			case 15 :
					this.shp1.setBgColor(this.color + " 0.3)");
					this.shp2.setBgColor(this.color + " 0)");
					this.shp3.setBgColor(this.color + " 0)");
					this.shp4.setBgColor(this.color + " 0)");
					this.shp5.setBgColor(this.color + " 0)");
					break;
		}
	},
	
	setMode : function(data)
	{
		switch (data)
		{
			case 1 :
					this.color = "rgba(255, 255, 255,";
					this.lbl.font.setColor("#FFFFFF");
					break;
			case 2 :
					this.color = "rgba(0, 0, 0,";
					this.lbl.font.setColor("#000000");
					break;
		}
	},
});
	
})();
